package algor

import "sync"

type StackInt struct {
	arr  []int
	lock sync.RWMutex
}

func (q *StackInt) Len() int {
	return len(q.arr)
}

func (q *StackInt) Push(i int) {
	q.lock.Lock()
	q.arr = append(q.arr, i)
	q.lock.Unlock()
}

func (q *StackInt) Pull() *int {
	q.lock.Lock()
	if q.Len() == 0 {
		return nil
	}

	v := q.arr[q.Len()-1]
	q.arr = q.arr[:q.Len()-1]
	q.lock.Unlock()
	return &v
}
